package xorm

import (
	"context"
	"database/sql"
	"gitee.com/KotlinToGo/xorm/dialect"
	"gitee.com/KotlinToGo/xorm/ictx"
	"gitee.com/KotlinToGo/xorm/log"
	"gitee.com/KotlinToGo/xorm/mapper"
	"gitee.com/KotlinToGo/xorm/schema"
	"reflect"
	"time"
)

var (
	_ Interface = &Session{}
	_ Interface = &Engine{}
	_ IEngine = &Engine{}
	_ IEngine = &EngineGroup{}
)

// Interface defines the interface which Engine, EngineGroup and Session will implementate.
type Interface interface {
	AllCols() *Session
	Alias(alias string) *Session
	Asc(colNames ...string) *Session
	SetBufSize(size int) *Session
	Field(columns ...string) *Session
	Count(...interface{}) (int64, error)
	CreateIndexes(bean interface{}) error
	CreateUniques(bean interface{}) error
	Decr(column string, arg ...interface{}) *Session
	Desc(...string) *Session
	Delete(interface{}) (int64, error)
	Distinct(columns ...string) *Session
	DropIndexes(bean interface{}) error
	Exec(sqlOrArgs ...interface{}) (sql.Result, error)
	Exist(bean ...interface{}) (bool, error)
	Find(interface{}, ...interface{}) error
	FindAndCount(interface{}, ...interface{}) (int64, error)
	Take(interface{}) (bool, error)
	GroupBy(keys string) *Session
	Id(interface{}) *Session
	In(string, ...interface{}) *Session
	Incr(column string, arg ...interface{}) *Session
	Insert(...interface{}) (int64, error)
	InsertOne(interface{}) (int64, error)
	IsTableEmpty(bean interface{}) (bool, error)
	IsTableExist(beanOrTableName interface{}) (bool, error)
	Iterate(interface{}, IterFunc) error
	Limit(int, ...int) *Session
	MustField(columns ...string) *Session
	NoAutoCondition(...bool) *Session
	NotIn(string, ...interface{}) *Session
	Join(joinOperator string, tablename interface{}, condition string, args ...interface{}) *Session
	Omit(columns ...string) *Session
	OrderBy(order string) *Session
	Ping() error
	QueryBytes(sqlOrArgs ...interface{}) (resultsSlice []map[string][]byte, err error)
	QueryInterface(sqlOrArgs ...interface{}) ([]map[string]interface{}, error)
	QueryStr(sqlOrArgs ...interface{}) ([]map[string]string, error)
	QueryValue(sqlOrArgs ...interface{}) ([]map[string]Value, error)
	QueryResult(sqlOrArgs ...interface{}) (result *ResultValue)
	Rows(bean interface{}) (*Rows, error)
	SetExpr(string, interface{}) *Session
	Select(string) *Session
	Sql(interface{}, ...interface{}) *Session
	Sum(bean interface{}, colName string) (float64, error)
	SumInt(bean interface{}, colName string) (int64, error)
	Sums(bean interface{}, colNames ...string) ([]float64, error)
	SumsInt(bean interface{}, colNames ...string) ([]int64, error)
	Table(tableNameOrBean interface{}) *Session
	Unscoped() *Session
	Update(bean interface{}, condiBeans ...interface{}) (int64, error)
	UseBool(...string) *Session
	Where(interface{}, ...interface{}) *Session
}

// EngineInterface defines the interface which Engine, EngineGroup will implementate.
type IEngine interface {
	Interface
	Before(func(interface{})) *Session
	Charset(charset string) *Session
	ClearCache(...interface{}) error
	Context(context.Context) *Session
	Create(...interface{}) error
	GetDBMeta() ([]*schema.Table, error)
	Dialect() dialect.IDialect
	GetDriver() string
	Drop(...interface{}) error
	DumpAllToFile(fp string, tp ...schema.DBType) error
	GetICache(string) schema.ICache
	GetColumnMapper() mapper.IMapper
	GetDefaultICache() schema.ICache
	GetTableMapper() mapper.IMapper
	GetTZDatabase() *time.Location
	GetTZLocation() *time.Location
	ImportFile(fp string) ([]sql.Result, error)
	MapICache(interface{}, schema.ICache) error
	NewSession() *Session
	NoAutoTime() *Session
	Quote(string) string
	SetICache(string, schema.ICache)
	SetConnMaxLifetime(time.Duration)
	SetColumnMapper(mapper.IMapper)
	SetDefaultICache(schema.ICache)
	SetLogger(logger interface{})
	SetLogLevel(log.LoggerLevel)
	SetMapper(mapper.IMapper)
	SetMaxOpenConns(int)
	SetMaxIdleConns(int)
	SetQuotePolicy(dialect.QuotePolicy)
	SetSchema(string)
	SetTableMapper(mapper.IMapper)
	SetTZDatabase(tz *time.Location)
	SetTZLocation(tz *time.Location)
	AddHook(hook ictx.IHook)
	ShowSQL(show ...bool)
	Sync(...interface{}) error
	Sync2(...interface{}) error
	StoreEngine(storeEngine string) *Session
	TableInfo(bean interface{}) (*schema.Table, error)
	TableName(interface{}, ...bool) string
	UnMapType(reflect.Type)
	SetSessionID(bool)
}


